import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useTaskStore = defineStore('task', () => {
  const tasks = ref([])
  
  // 模拟从API获取任务
  const fetchTasks = async () => {
    // 这里应该是API调用，暂时使用模拟数据
    tasks.value = [
      {
        id: 1,
        title: '清理丘丘人营地',
        description: '清除风龙废墟附近的丘丘人营地',
        reward: 40
      },
      {
        id: 2,
        title: '收集星螺',
        description: '为北斗船长收集10个星螺',
        reward: 20
      }
    ]
  }

  // 添加新任务
  const addTask = async (task) => {
    const newTask = {
      id: Date.now(),
      ...task
    }
    tasks.value.push(newTask)
  }

  // 删除任务
  const removeTask = async (id) => {
    tasks.value = tasks.value.filter(task => task.id !== id)
  }

  return {
    tasks,
    fetchTasks,
    addTask,
    removeTask
  }
})